

trait Creator {
   fn create(s: String) -> Self;
}

#[allow(dead_code)]
fn from<T>(s: String) -> T 
where T: Creator
{
    Creator::create(s)
}





#[derive(Debug)]
struct User {
    name: String,
}

impl Creator for User {
    fn create (name:String) -> Self {
        User::new(name)
    }
}
impl User {
    fn new(name: String) -> Self{
        Self {
            name,
        }
    }
    #[allow(dead_code)]
    fn get_name(&self) -> &str {
        &self.name
    }
}





#[derive(Debug)]
struct Teacher {
    name: String
}
impl Creator for Teacher {
    fn create(name: String) -> Self {
        Teacher::new(name)
    }
}
impl Teacher {
    fn new(name: String) -> Self{
        Self {
            name,
        }
    }
    #[allow(dead_code)]
    fn get_name(&self) -> &str {
        &self.name
    }
}


#[cfg(test)]
mod test {
    use super::*;

    #[test]
    fn create_user() {
        let s = "user.name".to_owned();
        //let v : User = Creator::create(s);
        let v : User = from(s);
        assert_eq!("user.name", v.get_name());
        //println!("{:?}", v);
    }
    #[test]
    fn create_teacher() {
        let s = "teacher.name".to_owned();
        let v : Teacher = from(s);
        assert_eq!("teacher.name", v.get_name());
        //println!("{:?}", v);
    }
}
